package com.zsy.petshop_01.service.impl;

import com.zsy.petshop_01.common.result.ResponseResult;
import com.zsy.petshop_01.model.entity.Product;
import com.zsy.petshop_01.model.vo.product.InsertVo;
import com.zsy.petshop_01.model.vo.product.UpdateVo;
import com.zsy.petshop_01.manager.ProductManager;
import com.zsy.petshop_01.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    ProductManager productManager;

    @Override
    public ResponseResult<?> selectAll() {
        List<Product> products = productManager.selectAll();
        return ResponseResult.success("OK", products);
    }

    @Override
    public ResponseResult<?> selectByName(String name) {
        List<Product> products = productManager.selectByName(name);
        return ResponseResult.success("OK", products);
    }

    @Override
    public ResponseResult<?> insert(InsertVo insertVo) {
        productManager.insert(insertVo);
        return ResponseResult.success("OK");
    }

    @Override
    public ResponseResult<?> update(UpdateVo updateVo) {
        productManager.update(updateVo);
        return ResponseResult.success("OK");
    }

    @Override
    public ResponseResult<?> delete(Integer id) {
        productManager.delete(id);
        return ResponseResult.success("OK");
    }
}
